let fn = async ([name, password], { socket, io, reg, user, NOTIFY, WARNING, USER_LOGIN, USER_INFO, FP }, topic) => {
    try {

        if (await reg.dao.verify(name, password)) {
            let oldUser = reg.users.find({name})
            if (oldUser) {
                oldUser.socket.emit(NOTIFY, { topic, data: '已在别处登录' })
                reg.users.remove(oldUser)
            }
            await reg.users.login(name, user)
            // 全局广播用户登录事件
            io.emit(USER_LOGIN, user.toSender())
            // 当前用户身份可能会变化
            socket.emit(FP, user.fp)
            socket.emit(USER_INFO, user.toSender())
        } else {
            socket.emit(NOTIFY, { topic, data: '用户名/密码错误' })
        }
    } catch ({ message }) {
        socket.emit(WARNING, {
            topic,
            data: message
        })
    }
}

module.exports = fn